package com.cyc.basic.service.redis;

import cn.hutool.bloomfilter.BloomFilterUtil;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @version 1.0
 * @author cyc
 * @date 2021/9/18 11:38
 */
@Component
public class RedissonTest {

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private StringRedisTemplate redisTemplate;

    private static final String REDIS_LOCK_KEY = "test";

    public void test() {
        RLock lock = redissonClient.getLock(REDIS_LOCK_KEY);

        try {
            lock.lock(20, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }


}
